﻿<m:ElevatorAutomaton 
    x:Class="Rhizome.QuickStart.Elevator.Model.Door" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:m="clr-namespace:Rhizome.QuickStart.Elevator.Model" 
	xmlns:r="clr-namespace:Rhizome.Model;assembly=Rhizome.Core" 
	InitialState="Opened" 
    >

    <m:ElevatorAutomaton.Edges>

        <r:Edge State="Opened">
            <r:Transition Event="Close" State="Closed" />
        </r:Edge>

        <r:Edge State="Closed">
            <r:Transition Event="Open" State="Opened" />
        </r:Edge>

    </m:ElevatorAutomaton.Edges>

    <m:ElevatorState Id="Opened">
        <r:EntryActions>
            <r:SetBool Property="IsOpen" Value="True" />
            <r:SetInt Property="TimeOut" Value="0" />
        </r:EntryActions>
		
		<!--
		Just another syntax
		<r:OnEntry Action="IsOpen=True; TimeOut=0" />
		-->

        <m:DoorTrigger Event="Close" Criterion="UpChecked || DownChecked" />

    	<r:Trigger Property="TimeOut" Criterion="TimeOut == 10" Action="IsOpen = False" />
		<!--
		Criterion="TimeOut == 10" sets Criterion = new IfEquals<int>("TimeOut", 10)
		-->
    	<r:Counter Property="TimeOut" Period="00:00:01" Step="1" />

		<r:OnExit Action="IsOpen=False" />
    </m:ElevatorState>
    
    <m:ElevatorState Id="Closed">

        <m:DoorTrigger Event="Open" Criterion="UpChecked == False * !DownChecked" />

        <!-- 
			AND: * or &amp;
			OR: ||
		-->

        <!--
			Just another syntax without TypeConverter
			
			<r:DoorTrigger.Criterion>
                <r:AndCriterion If="UpChecked == False" And="DownChecked == False" />
            </r:DoorTrigger.Criterion>
        -->

    </m:ElevatorState>

</m:ElevatorAutomaton>